﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Classes.effects.*;
    import Display.MarketUI.*;
    import Display.LotUI.*;
    import Engine.*;

    public class LotSite extends MapResource {

        public static const LOT_NAME:String = "biz_lotsite_4x4";

        protected const TYPE_NAME:String = "lot_site";
        protected const STATE_STATIC:String = "static";

        protected var m_pick:DisplayObject;
        protected var m_isListeningToRender:Boolean;

        public function LotSite(_arg1:String){
            super(_arg1);
            m_objectType = WorldObjectTypes.LOT_SITE;
            m_typeName = this.TYPE_NAME;
            setState(this.STATE_STATIC);
            if (Global.isVisiting()){
                addAnimatedEffect(EffectType.SPARKLE);
            };
        }
        public static function onFranchisePendingClick():void{
            var _local3:LotSite;
            var _local1:Array = Global.world.getObjectsByTypes([WorldObjectTypes.LOT_SITE]);
            if (BuyLogic.isAtMaxFranchiseCount()){
                return;
            };
            if (_local1.length == 0){
                Global.guide.notify("FranchiseRequestEligible");
                return;
            };
            var _local2:int;
            while (_local2 < _local1.length) {
                _local3 = _local1[_local2];
                if (_local3.m_pick != null){
                    Global.world.centerOnIsoPosition(_local3.getPosition(), 0);
                };
                _local2++;
            };
        }
        public static function shouldShowFranchiseMQIcon():Boolean{
            return ((((((Global.world.citySim.lotManager.receivedPendingOrders.length > 0)) && (!(Global.isVisiting())))) && (BuyLogic.canAcceptFranchiseRequests(Global.player.uid))));
        }

        public function get targetType():String{
            return (m_item.type);
        }
        public function getPick():DisplayObject{
            return (this.m_pick);
        }
        public function setPick(_arg1:DisplayObject):void{
            this.removePick();
            this.m_pick = _arg1;
            this.attachPick();
        }
        public function removePick():void{
            if (((this.m_pick) && (this.m_pick.parent))){
                this.m_pick.parent.removeChild(this.m_pick);
                this.cleanUpPick();
            };
            this.m_pick = null;
        }
        public function updatePick():void{
            if (((this.m_pick) && (this.m_pick.parent))){
                this.m_pick.parent.setChildIndex(this.m_pick, (this.m_pick.parent.numChildren - 1));
            };
        }
        protected function attachPick():void{
            if (((((((m_content) && (this.m_pick))) && (!((this.m_pick.parent == m_displayObject))))) && (!(GlobalEngine.viewport.hudBase.contains(this.m_pick))))){
                GlobalEngine.viewport.hudBase.addChild(this.m_pick);
                this.addRenderListener();
                m_isHighlightable = true;
            } else {
                if (!Global.isVisiting()){
                };
            };
        }
        override public function isPixelInside(_arg1:Point):Boolean{
            var _local2:SlidePickGroup;
            if (((this.m_pick) && ((this.m_pick is SlidePickGroup)))){
                _local2 = (this.m_pick as SlidePickGroup);
                if (_local2.isTopSlidePickOpened){
                    return (true);
                };
            };
            return (super.isPixelInside(_arg1));
        }
        protected function setPickPosition():void{
            var _local1:Point = new Point(-30, -150);
            var _local2:Point = IsoMath.tilePosToPixelPos(m_position.x, m_position.y);
            _local2 = IsoMath.viewportToStage(_local2);
            this.m_pick.x = (_local2.x + _local1.x);
            this.m_pick.y = (_local2.y + _local1.y);
        }
        protected function addRenderListener():void{
            if (((!(this.m_isListeningToRender)) && (!((Global.stage == null))))){
                Global.stage.addEventListener(Event.RENDER, this.renderHandler, false, 0, true);
                this.m_isListeningToRender = true;
                this.setPickPosition();
            };
        }
        protected function removeRenderListeners():void{
            if (Global.stage != null){
                Global.stage.removeEventListener(Event.RENDER, this.renderHandler);
            };
            this.m_isListeningToRender = false;
        }
        protected function renderHandler(_arg1:Event):void{
            this.setPickPosition();
        }
        override public function onPlayAction():void{
            super.onPlayAction();
            if (((this.m_pick) && (this.m_pick.hasOwnProperty("onClick")))){
                var _local1 = this.m_pick;
                _local1["onClick"]();
            } else {
                if (!Global.isVisiting()){
                    FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_EMPTYLOT);
                };
            };
        }
        override public function drawDisplayObject():void{
            super.drawDisplayObject();
            this.attachPick();
        }
        override public function onUpdate(_arg1:Number):void{
            super.onUpdate(_arg1);
            this.attachPick();
        }
        override public function cleanUp():void{
            this.removePick();
            super.cleanUp();
        }
        private function cleanUpPick():void{
            if (((this.m_pick) && (this.m_pick.hasOwnProperty("cleanUp")))){
                var _local1 = this.m_pick;
                _local1["cleanUp"]();
            };
            this.removeRenderListeners();
        }
        override public function getToolTipPosition():Vector3{
            var _local2:Number;
            var _local1:Vector3 = getPosition();
            if (((this.m_pick) && (this.m_pick.visible))){
                _local2 = 3;
                _local1.x = (_local1.x + _local2);
                _local1.y = (_local1.y + _local2);
            };
            return (_local1);
        }
        override public function isSellable():Boolean{
            return (true);
        }
        override public function onSell():void{
            Global.world.citySim.lotManager.removeLotSite(this);
            super.onSell();
        }
        override public function onObjectDrop(_arg1:Vector3):void{
            super.onObjectDrop(_arg1);
            Global.world.citySim.lotManager.addLotSite(this);
        }
        public function remove():void{
            this.detach();
            this.cleanUp();
        }
        override public function onMouseOver(_arg1:MouseEvent):void{
            super.onMouseOver(_arg1);
            this.updatePick();
        }
        override public function getToolTipStatus():String{
            var _local1:String;
            if (!Global.isVisiting()){
                if (this.m_pick){
                    _local1 = ZLoc.t("Main", "BusinessZone1HomeRequest");
                } else {
                    _local1 = ZLoc.t("Main", "BusinessZone1Home");
                };
            } else {
                _local1 = ZLoc.t("Main", "BusinessZone1Visit");
            };
            return (_local1);
        }
        override public function getToolTipVisibility():Boolean{
            return (true);
        }
        override public function onBuildingConstructionCompleted_PreServerUpdate():void{
            FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_EMPTYLOT);
            Global.world.citySim.lotManager.addLotSite(this);
        }
        override public function get isEmptyLot():Boolean{
            return (true);
        }

    }
}//package Classes 
